package de.amaly.wosdemdes.persistence;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import de.amaly.wosdemdes.persistence.DatabaseContract.ShowProgressEntryTable;

/**
 * A {@link SQLiteOpenHelper} helper class for managing database access within the WoSDeMDeS app.
 * 
 * @author Andreas Maly
 * 
 */
public class DatabaseHelper extends SQLiteOpenHelper {

    // If the database schema changes, the database version must be incremented
    public static final int DATABASE_VERSION = 1;
    public static final String DATABASE_NAME = "WoSDeMDeS.db";

    // Strings for creating the database
    private static final String TEXT_TYPE = " TEXT";
    private static final String INTEGER_TYPE = " INTEGER";
    private static final String COMMA_SEP = ",";

    // Create statement for the (currently single) database table
    private static final String SQL_CREATE_SHOW_PROGRESS_ENTRY_TABLE = "CREATE TABLE "
            + ShowProgressEntryTable.TABLE_NAME + " (" + ShowProgressEntryTable._ID + INTEGER_TYPE + " PRIMARY KEY"
            + COMMA_SEP + ShowProgressEntryTable.COLUMN_SHOW_NAME + TEXT_TYPE + COMMA_SEP
            + ShowProgressEntryTable.COLUMN_SEASON_NUMBER + INTEGER_TYPE + COMMA_SEP
            + ShowProgressEntryTable.COLUMN_EPISODE_NUMBER + INTEGER_TYPE + COMMA_SEP
            + ShowProgressEntryTable.COLUMN_DISC_NUMBER + INTEGER_TYPE + COMMA_SEP
            + ShowProgressEntryTable.COLUMN_PROGRESS_COMMENT + TEXT_TYPE + ")";


    /**
     * Creates a new {@link DatabaseHelper}
     * 
     * @param context
     */
    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_SHOW_PROGRESS_ENTRY_TABLE);
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // Do nothing
    }
}
